# -*- coding:utf-8 -*-

from server.action.batchBase import batchBase
from server.util import sqlBuild, stringUtil


class lreg(batchBase):  # 灯端从属关系初始化
    def action(self, data, d):
        baId, lcId = data[0], data[2]
        ss = stringUtil.redis_key_name(baId, "ss")
        lb = stringUtil.redis_key_name(baId)
        seId = self.re.lindex(lb, 0)

        initSql = sqlBuild.sqlDict["update_lampClient_init"] % (baId, lcId)  # 更新从属关系
        stateSql = sqlBuild.sqlDict["update_lampClient_state"] % (0, lcId)  # 更新灯端状态（重启时必然为关闭状态）
        self.db.update(initSql, stateSql)

        taskStr = baId + ",seid" + "," + lcId + "," + seId
        self.re.zadd(ss, taskStr, 0)

        d.callback((2,))
        # d.callback((1, (baId, "seid", lcId, seId), baId))
